import requests

url = 'https://flk.npc.gov.cn/api/?page=3&type=flfg&xlwj=02&xlwj=03&xlwj=04&xlwj=05&xlwj=06&xlwj=07&xlwj=08&searchType=title%3Bvague&sortTr=f_bbrq_s%3Bdesc&gbrqStart=&gbrqEnd=&sxrqStart=&sxrqEnd=&sort=true&size=10&_=1676027644310'
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'
}
json_data = requests.get(url=url, headers=headers).json()
print(json_data)
for index in json_data['result']['data']:
    word_id = index['id']
    title = index['title']
    print(word_id, title)
    link = 'https://flk.npc.gov.cn/api/detail'
    data = {
        'id': word_id
    }
    response = requests.post(url=link, data=data, headers=headers)
    word_download = 'https://wb.flk.npc.gov.cn' + response.json()['result']['body'][0]['path']
    name = response.json()['result']['body'][0]['path'].split('.')[-1]
    print(word_download)
    content = requests.get(url=word_download, headers=headers).content
    with open('data\\' + title + '.' + name, mode='wb') as f:
        f.write(content)
